
export function isApp() {
    if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
        //alert(navigator.userAgent);
        alert('这是IOS');
    } else if (/(Android)/i.test(navigator.userAgent)) {
        //alert(navigator.userAgent);
        alert('这是Android');
    } else {
        alert('这是PC');
    }
}

export function formatTime(date = new Date(), formatStr = 'YYYY-MM-DD HH:mm:ss') {
    if (!date) return '';
    const d = new Date(date);
    if (isNaN(d.getTime())) return '';
    const pad = (num) => num.toString().padStart(2, '0');
    return formatStr
        .replace(/YYYY/g, d.getFullYear())
        .replace(/YY/g, d.getFullYear().toString().slice(-2))
        .replace(/MM/g, pad(d.getMonth() + 1))
        .replace(/DD/g, pad(d.getDate()))
        .replace(/HH/g, pad(d.getHours()))
        .replace(/mm/g, pad(d.getMinutes()))
        .replace(/ss/g, pad(d.getSeconds()));
}

export function toTree(arr) {
    let ret = [];
    let tree = {};
    for (let i = 0; i < arr.length; i++) {
        let obj = arr[i];
        if (obj.label === undefined) {
            obj.label = 'other';
        }
        if (tree[obj.label] !== undefined) {
            tree[obj.label].push(obj);
        } else {
            tree[obj.label] = [obj];
            ret.push({
                label: obj.label,
                data: tree[obj.label]
            });
        }
    }

    return ret;
}

export function getUserInfoByToken() {
    return undefined;
}
